package com.jhx.mall.dao.impl;

import com.jhx.mall.dao.BaseDao;
import com.jhx.mall.dao.DtsAdDao;
import com.jhx.mall.entity.DtsAd;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class DtsAdDaoImpl extends BaseDao implements DtsAdDao {
    @Override
    public List<DtsAd> selectAll() {
        List<DtsAd> adList = new ArrayList<>();
        String sql = "select id, name, link, url, position, content, start_time, end_time, enabled, add_time, update_time, deleted from dts_ad where deleted = 0";
        rs = super.executeQuery(sql);
        try {
            while (rs.next()) {
                DtsAd ad = new DtsAd();
                ad.setId(rs.getLong("id"));
                ad.setName(rs.getString("name"));
                ad.setLink(rs.getString("link"));
                ad.setUrl(rs.getString("url"));
                ad.setPosition(rs.getLong("position"));
                ad.setContent(rs.getString("content"));
                ad.setStartTime(rs.getString("start_time"));
                ad.setEndTime(rs.getString("end_time"));
                ad.setEnabled(rs.getLong("enabled"));
                ad.setAddTime(rs.getString("add_time"));
                ad.setUpdateTime(rs.getString("update_time"));
                ad.setDeleted(rs.getLong("deleted"));
                adList.add(ad);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            super.closeAll(rs, pstmt, conn);
        }
        return adList;
    }
}
